import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 4000, // 设置服务启动端口号
    open: true, // 设置服务启动时是否自动打开浏览器
    cors: true, // 允许跨域

    // 设置代理，根据我们项目实际情况配置
    proxy: {
      '/Mercure': { //apiTest是自行设置的请求前缀，按照这个来匹配请求，有这个字段的请求，就会进到代理来
        target: 'https://www.fastmock.site/mock/d7a90c8f40af1ba65e83d21580134479',
        changeOrigin: true, //是否跨域
        // rewrite: (path) => path.replace('/apiTest', '') //重写匹配的字段，如果不需要放在请求路径上，可以重写为""
      },
      '/queryList.do': {
        target: 'https://www.bthome.com/os-service/content/case/',
        changeOrigin: true, //是否跨域
        // rewrite: (path) => path.replace('/apiTest', '') //重写匹配的字段，如果不需要放在请求路径上，可以重写为""
      },
      '/api': {
        target: 'https://homed.snssdk.com/homed/',
        // https://homed.snssdk.com/homed
        changeOrigin: true,
      },
      '/Designer': {
        target: 'https://mp-yapi.haohaozhu.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace('/Designer', '')
      }
    }
  }

})